package org.codeart.factory.scheme01.controller;

import org.codeart.factory.scheme01.pojo.AwardInfo;
import org.codeart.factory.scheme01.pojo.GiftInfo;
import org.codeart.factory.scheme01.service.DiscountService;
import org.codeart.factory.scheme01.service.GiftService;
import org.codeart.factory.scheme01.service.VideoVipService;

import java.util.Map;
import java.util.UUID;

/**
 * 奖品发放接口
 */
public class DeliverController {

    /**
     * 按照类型不同发放
     * 奖品类型 1：打折券  2：视频会员  3：小礼品
     */
    public void deliverAward(AwardInfo awardInfo) {
        Map<String, String> extraInfo = awardInfo.getExtraInfo();
        if (awardInfo.getAwardType() == 1) {
            DiscountService discountService = new DiscountService();
            discountService.sendDiscount(awardInfo.getUid(), awardInfo.getAwardNumber());
            System.out.println("打折券发放成功！");
        } else if (awardInfo.getAwardType() == 2) {
            String phone = extraInfo.get("phone");
            VideoVipService videoVipService = new VideoVipService();
            videoVipService.openMembership(phone, awardInfo.getAwardNumber());
            System.out.println("视频会员发放成功！");
        } else if (awardInfo.getAwardType() == 3) {
            GiftInfo giftInfo = new GiftInfo();
            giftInfo.setUsername(extraInfo.get("username"))
                    .setPhone(extraInfo.get("phone"))
                    .setAddress(extraInfo.get("address"))
                    .setOrderId(UUID.randomUUID().toString());
            GiftService giftService = new GiftService();
            Boolean b = giftService.deliverGift(giftInfo);
            if (b) {
                System.out.println("小礼品发放成功！");
            }
        }
    }

}
